import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select


def run(url):
    options = webdriver.ChromeOptions()
    options.add_argument(
        'user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36 Edg/86.0.622.69"')  # 添加UA属性
    options.add_experimental_option("excludeSwitches", ["enable-automation"])  # 设置开发者模式启动，该模式下webdriver属性为正常值
    options.add_experimental_option('useAutomationExtension', False)
    # options.add_experimental_option("detach", True)
    driver = webdriver.Chrome(options=options)
    driver.maximize_window()
    driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
        "source": """
                                Object.defineProperty(navigator, 'webdriver', {
                                  get: () => undefined
                                })
                              """
    })
    driver.get(url)
    time.sleep(2)
    try:
        driver.switch_to.frame(0)
        Select(driver.find_element(By.XPATH, '//*[@id="province"]')).select_by_visible_text("广东省")
        time.sleep(1)
        Select(driver.find_element(By.XPATH, '//*[@id="city"]')).select_by_visible_text("深圳市")
        time.sleep(1)
        driver.find_element(By.XPATH, '/html/body/div[2]/div[9]/div[3]').click()
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div[2]/div[10]/div[4]').click()
        time.sleep(20)
    except:
        pass
